<template>
    <div class="container-content">
        <!-- <el-row>
          <el-col :span="24">
              <h3 class="panel-title">新建客户</h3>
          </el-col>
      </el-row> -->
        <el-form
            ref="formObjectRef"
            :model="formObject"
            label-width="100px"
            :rules="formObjectRules"
            status-icon
            label-position="left"
        >
            <el-dropdown
                style="position: absolute; right: 50px; top: 20px; z-index: 10"
                trigger="click"
                @command="handleCommand"
            >
                <el-button size="small" type="primary">
                    选单<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command="procurementContract"
                        >采购合同</el-dropdown-item
                    >
                    <el-dropdown-item command="payApply"
                        >采购申请单</el-dropdown-item
                    >
                    <el-dropdown-item command="saleOrder"
                        >销售订单</el-dropdown-item
                    >
                    <el-dropdown-item command="askSheet"
                        >询价单</el-dropdown-item
                    >
                </el-dropdown-menu>
            </el-dropdown>
            <el-collapse v-model="activeName" @change="handleClick">
                <el-collapse-item title="基本信息" name="basic">
                    <div class="desc-title">基本信息</div>
                    <el-row :gutter="20">
                        <el-col v-if="rowId" :span="8">
                            <el-form-item label="单据类型" prop="docType">
                                <el-input
                                    :disabled="true"
                                    style="width: 100%"
                                    v-model="formObject.docType"
                                    :props="props"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col v-if="!rowId" :span="8">
                            <el-form-item label="单据类型" prop="docType">
                                <el-select
                                    v-model="formObject.docType"
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in documentTypeList"
                                        :key="item.docCode"
                                        :label="item.title"
                                        :value="item.docCode"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="单据编号" prop="documentCode">
                                <el-input
                                    v-model="formObject.documentCode"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="供应商" prop="supplierName">
                                <el-input v-model="formObject.supplierName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('supplierId')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="采购员" prop="applyName">
                                <el-input v-model="formObject.applyName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('applyName')"
                                    ></i
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <!-- <el-col :span="8">
              <el-form-item label="业务类型" prop="docBusinessType">
                <el-input :disabled="true" v-model="docBusinessType"></el-input>
              </el-form-item>
            </el-col> -->
                        <el-col :span="8">
                            <!-- <el-form-item label="采购组织" prop="purchaseOrgLabel">
                <el-input v-model="formObject.purchaseOrgLabel">
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('deptId')"
                  ></i>
                </el-input>
              </el-form-item> -->
                        </el-col>
                        <el-col :span="8">
                            <!-- <el-col :span="8">
                            <el-form-item
                                label="单据状态"
                                prop="companyWebsite"
                            >
                                <el-input
                                    v-model="formObject.companyWebsite"
                                ></el-input>
                            </el-form-item>
                        </el-col> -->

                            <el-form-item
                                label="采购部门"
                                prop="purchaseOrgLabel"
                            >
                                <el-input v-model="formObject.purchaseOrgLabel">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('deptId')"
                                    ></i
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="采购日期" prop="applyTime">
                                <el-date-picker
                                    v-model="formObject.applyTime"
                                    type="datetime"
                                    placeholder="请选择采购日期"
                                    style="width: 100%"
                                    value-format="yyyy-MM-dd"
                                    format="yyyy-MM-dd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="采购组" prop="purchaseGroup">
                                <el-input
                                    v-model="formObject.purchaseGroup"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="验收方式" prop="checkMethod">
                                <el-select
                                    v-model="formObject.checkMethod"
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in checkMethodList"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="项目名称" prop="projectId">
                                <el-input
                                    v-model="formObject.projectId"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="仓库" prop="warehouseId">
                                <el-select
                                    v-model="formObject.warehouseId"
                                    placeholder="请选择"
                                    style="width: 100%"
                                >
                                    <el-option
                                        v-for="item in warehouseList"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label-width="110px"
                                label="厂家出库时间"
                                prop="factoryTime"
                            >
                                <el-date-picker
                                    v-model="formObject.factoryTime"
                                    type="datetime"
                                    placeholder="请选择日期"
                                    style="width: 100%"
                                    value-format="yyyy-MM-dd"
                                    format="yyyy-MM-dd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col v-if="rowId" :span="8">
                            <el-form-item label="变更原因" prop="changeReason">
                                <el-input
                                    type="textarea"
                                    v-model="formObject.changeReason"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <div class="desc-title">财务信息</div>
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item
                                label="结算币别"
                                prop="settlementCurrencyName"
                            >
                                <el-input
                                    v-model="formObject.settlementCurrencyName"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('settlementCurrency')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="付款条件"
                                prop="termOfPaymentTitle"
                            >
                                <el-input
                                    v-model="formObject.termOfPaymentTitle"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('termOfPayment')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="结算方式"
                                prop="settlementMethodName"
                            >
                                <el-input
                                    v-model="formObject.settlementMethodName"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('settlementMethod')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="汇率类型"
                                prop="exchangeRateType"
                            >
                                <el-input v-model="formObject.exchangeRateType">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('exchangeRateType')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="汇率" prop="exchangeRate">
                                <el-input
                                    disabled
                                    v-model="formObject.exchangeRate"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="价目表" prop="priceInfoName">
                                <el-input v-model="formObject.priceInfoName">
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('priceInfoId')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="折扣表"
                                prop="discountInfoIName"
                            >
                                <el-input
                                    v-model="formObject.discountInfoIName"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('discountInfoId')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="定价时点"
                                prop="pricingTimePoint"
                            >
                                <el-date-picker
                                    v-model="formObject.pricingTimePoint"
                                    type="datetime"
                                    placeholder="请选择定价时点日期"
                                    style="width: 100%"
                                    value-format="yyyy-MM-dd"
                                    format="yyyy-MM-dd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="集中结算组织"
                                prop="focusSettlementDept"
                            >
                                <el-input
                                    v-model="formObject.focusSettlementDept"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <!-- <el-col :span="8">
              <el-form-item label="保证金比例" prop="correspondingOrganization">
                <el-input
                  v-model="formObject.correspondingOrganization"
                ></el-input>
              </el-form-item>
            </el-col> -->
                        <el-col :span="8">
                            <el-form-item
                                label="整单折扣额"
                                prop="wholeDiscountAmount"
                            >
                                <el-input
                                    v-model="formObject.wholeDiscountAmount"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="税额" prop="taxAmount">
                                <el-input
                                    v-model="formObject.taxAmount"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="金额" prop="moneyAmount">
                                <el-input
                                    v-model="formObject.moneyAmount"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="价税合计" prop="totalPriceTax">
                                <el-input
                                    v-model="formObject.totalPriceTax"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="本位币"
                                prop="baseCurrencyName"
                            >
                                <el-input
                                    disabled
                                    v-model="formObject.baseCurrencyName"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="本位币税额"
                                prop="taxAmountBase"
                            >
                                <el-input
                                    disabled
                                    v-model="formObject.taxAmountBase"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label-width="150px"
                                label="本位币价税合计"
                                prop="totalPriceTaxBase"
                            >
                                <el-input
                                    disabled
                                    v-model="formObject.totalPriceTaxBase"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="本位币金额"
                                prop="moneyAmountBase"
                            >
                                <el-input
                                    disabled
                                    v-model="formObject.moneyAmountBase"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label-width="160px"
                                label="累计付款申请费金额"
                                prop="totalPaymentApplyAmount"
                            >
                                <el-input
                                    v-model="formObject.totalPaymentApplyAmount"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label-width="160px"
                                label="申请单未付款累计金额"
                                prop="applyFormUnpaidAmount"
                            >
                                <el-input
                                    v-model="formObject.applyFormUnpaidAmount"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="累计付款金额"
                                prop="groupSupplier"
                            >
                                <el-input
                                    v-model="formObject.groupSupplier"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label-width="160px"
                                label="订单未付款金额"
                                prop="totalPaymentAmount"
                            >
                                <el-input
                                    v-model="formObject.totalPaymentAmount"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="累计退款金额"
                                prop="totalReturnAmount"
                            >
                                <el-input
                                    v-model="formObject.totalReturnAmount"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-form-item>
                                <el-checkbox v-model="formObject.isTax"
                                    >含税</el-checkbox
                                >
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-form-item>
                                <el-checkbox
                                    v-model="formObject.isExtraPriceTax"
                                    >价外税</el-checkbox
                                >
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <div class="desc-title">供应商信息</div>
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item label="供货方" prop="providerName">
                                <el-input
                                    v-model="
                                        formObject.orderSupplier.providerName
                                    "
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('providerId')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label="供货方联系人"
                                prop="providerContacts"
                            >
                                <el-input
                                    v-model="
                                        formObject.orderSupplier
                                            .appproviderContactslyId
                                    "
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="职务" prop="post">
                                <el-input
                                    v-model="formObject.orderSupplier.post"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="手机" prop="phone">
                                <el-input
                                    v-model="formObject.orderSupplier.phone"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="供货方地址" prop="address">
                                <el-input
                                    v-model="formObject.orderSupplier.address"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="结算方" prop="balanceName">
                                <el-input
                                    v-model="
                                        formObject.orderSupplier.balanceName
                                    "
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('balanceId')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="收款方" prop="receiveName">
                                <el-input
                                    v-model="
                                        formObject.orderSupplier.receiveName
                                    "
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="addDialog('receiveId')"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item label="邮箱" prop="email">
                                <el-input
                                    v-model="formObject.orderSupplier.email"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-collapse-item>
                <!-- <el-collapse-item title="订单条款" name="orderPurchaseTerms">
                    <el-button
                        type="text"
                        @click="addNewRow('orderPurchaseTerms')"
                        >新增行</el-button
                    >
                    <el-table
                        :data="formObject.orderPurchaseTerms"
                        style="width: 100%"
                        highlight-current-row
                        border
                    >
                        <el-table-column label="操作" width="60">
                            <template slot-scope="scope">
                                <el-button
                                    plain
                                    icon="el-icon-minus"
                                    size="mini"
                                    @click="
                                        handleDataDelete(
                                            scope.$index,
                                            scope.row,
                                            'orderPurchaseTerms'
                                        )
                                    "
                                ></el-button>
                            </template>
                        </el-table-column>
                        <el-table-column label="条款编码">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="id"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input v-model="scope.row.id">
                                        <i
                                            slot="suffix"
                                            class="el-input__icon el-icon-notebook-2"
                                            style="cursor: pointer"
                                            @click="
                                                addDialog(
                                                    'termsId',
                                                    scope.$index
                                                )
                                            "
                                        ></i>
                                    </el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="条款名称" width="150">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="name"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.name"
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="条款类型">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="sex"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-select
                                        v-model="scope.row.sex"
                                        placeholder="请选择"
                                        style="width: 100%"
                                    >
                                        <el-option
                                            key="0"
                                            label="男"
                                            value="0"
                                        ></el-option>
                                        <el-option
                                            key="1"
                                            label="女"
                                            value="1"
                                        ></el-option>
                                        <el-option
                                            key="2"
                                            label="未知"
                                            value="2"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="条款内容">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="describe"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.describe"
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="描述">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="workTel"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.workTel"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-collapse-item> -->
                <el-collapse-item title="明细信息" name="orderDetails">
                    <el-button
                        type="text"
                        size="medium"
                        @click="addDialog('addmaterial')"
                        >新增物料</el-button
                    >
                    <el-table
                        :data="formObject.orderDetails"
                        style="width: 100%"
                        highlight-current-row
                        @selection-change="handleSelectionChange(orderDetails)"
                        border
                    >
                        <el-table-column label="操作" width="60">
                            <template slot-scope="scope">
                                <el-button
                                    plain
                                    icon="el-icon-minus"
                                    size="mini"
                                    @click="
                                        handleDataDelete(
                                            scope.$index,
                                            scope.row,
                                            'orderDetails'
                                        )
                                    "
                                ></el-button>
                            </template>
                        </el-table-column>
                        <el-table-column width="200" label="物料编码">
                            <template slot-scope="scope">
                                <el-form-item
                                    label-width="0px"
                                    style="margin: 0"
                                    :rules="formObjectRules.materialCode"
                                    :prop="
                                        'orderDetails.' +
                                        scope.$index +
                                        '.materialCode'
                                    "
                                >
                                    <el-input
                                        @focus="
                                            addDialog('material', scope.$index)
                                        "
                                        v-model="scope.row.materialCode"
                                    >
                                        <i
                                            slot="suffix"
                                            @click="
                                                addDialog(
                                                    'material',
                                                    scope.$index
                                                )
                                            "
                                            class="el-input__icon el-icon-notebook-2"
                                            style="cursor: pointer"
                                        ></i>
                                    </el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="150" label="物料名称">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="materialName"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        disabled
                                        v-model="scope.row.materialName"
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="150" label="规格型号">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="model"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        disabled
                                        v-model="scope.row.model"
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <!-- <el-table-column width="200" label="采购单位">
              <template slot-scope="scope">
                <el-form-item
                  prop="purchaseUnit"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.purchaseUnit"></el-input>
                </el-form-item>
              </template>
            </el-table-column> -->
                        <el-table-column
                            width="120"
                            v-if="rowId"
                            label="原采购数量"
                        >
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="originalNumber"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        :disabled="true"
                                        v-model="scope.row.originalNumber"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="采购数量">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="number"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        @change="
                                            changeNumber(
                                                scope.$index,
                                                scope.row
                                            )
                                        "
                                        v-model="scope.row.number"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="200" label="交货日期">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="deliveryDate"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-date-picker
                                        style="width: 100%"
                                        v-model="scope.row.deliveryDate"
                                        type="date"
                                        placeholder="选择交货日期"
                                    >
                                    </el-date-picker>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="计价单位">
                            <template slot-scope="scope">
                                <el-form-item
                                    :rules="formObjectRules.pricingUnitName"
                                    :prop="
                                        'orderDetails.' +
                                        scope.$index +
                                        '.pricingUnitName'
                                    "
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        readonly
                                        v-model="scope.row.pricingUnitName"
                                        clearable
                                        ><i
                                            slot="suffix"
                                            @click="
                                                addDialog('Unit', scope.$index)
                                            "
                                            class="el-input__icon el-icon-notebook-2"
                                            style="cursor: pointer"
                                        ></i
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="计价数量">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="pricingNum"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.pricingNum"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="单价">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="price"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        disabled
                                        v-model="scope.row.price"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column
                            width="120"
                            v-if="rowId"
                            label="原含税单价"
                        >
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="originalContainsTaxPrice"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        :disabled="true"
                                        v-model="
                                            scope.row.originalContainsTaxPrice
                                        "
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="含税单价">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="taxPrice"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        disabled
                                        v-model="scope.row.taxPrice"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column width="120" label="折扣率%">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="discountRate"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.discountRate"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="折扣额">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="discountAmount"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        disabled
                                        v-model="scope.row.discountAmount"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="税率%">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="taxRate"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        @change="
                                            changeNumber(
                                                scope.$index,
                                                scope.row
                                            )
                                        "
                                        v-model="scope.row.taxRate"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="税额">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="taxAmount"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        disabled
                                        v-model="scope.row.taxAmount"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="价税合计">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="totalTaxPrice"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        @change="
                                            changeNumber(
                                                scope.$index,
                                                scope.row
                                            )
                                        "
                                        v-model="scope.row.totalTaxPrice"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="金额">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="amountMoney"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        disabled
                                        v-model="scope.row.amountMoney"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="150" label="直接汇率">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="directRate"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        @change="
                                            rateChange(scope.row, scope.$index)
                                        "
                                        v-model="scope.row.directRate"
                                        clearable
                                    >
                                        <i
                                            slot="suffix"
                                            class="el-input__icon el-icon-notebook-2"
                                            style="cursor: pointer"
                                            @click="
                                                addDialog('rate', scope.$index)
                                            "
                                        ></i>
                                    </el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="150" label="间接汇率">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="indirectRate"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.indirectRate"
                                        disabled
                                        clearable
                                    >
                                    </el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="净价">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="netAmount"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.netAmount"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="200" label="需求组织">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="requireDept"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.requireDept"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="200" label="收料组织">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="receivingDept"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.receivingDept"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="100" label="是否赠品">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="isGiveaway"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-checkbox
                                        :v-model="scope.row.isGiveaway"
                                        clearable
                                    />
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="200" label="备注">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="remark"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.remark"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="200" label="供应商物料编码">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="supplierMaterialCode"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.supplierMaterialCode"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="200" label="供应商物料名称">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="supplierMaterialName"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.supplierMaterialName"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="库存单位">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="inventoryUnit"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.inventoryUnit"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="库存单位数量">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="inventoryNum"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.inventoryNum"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="累计验收金额">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="totalAcceptanceAmount"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="
                                            scope.row.totalAcceptanceAmount
                                        "
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="120" label="累计验收比例%">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="totalAcceptanceRate"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.totalAcceptanceRate"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="150" label="业务含税成本单价">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="totalAcceptanceRate"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.totalAcceptanceRate"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column width="200" label="批次号">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="batchNum"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.batchNum"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <!-- <el-table-column label="验收票数量（库存基本）">
              <template slot-scope="scope">
                <el-form-item prop="userId" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.userId" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column> -->
                    </el-table>
                </el-collapse-item>
                <!-- <el-collapse-item title="付款计划" name="orderPaymentPlans">
                    <el-button
                        type="text"
                        @click="addNewRow('orderPaymentPlans')"
                        >新增行</el-button
                    >
                    <el-table
                        :data="formObject.orderPaymentPlans"
                        style="width: 100%"
                        highlight-current-row
                        border
                    >
                        <el-table-column label="操作" width="120">
                            <template slot-scope="scope">
                                <el-button
                                    plain
                                    icon="el-icon-minus"
                                    size="mini"
                                    @click="
                                        handleDataDelete(
                                            scope.$index,
                                            scope.row,
                                            'orderPaymentPlans'
                                        )
                                    "
                                ></el-button>
                            </template>
                        </el-table-column>

                        <el-table-column label="采购订单id">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="orderId"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.orderId"
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="实际预付金额">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="actualPrepaidAmount"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.actualPrepaidAmount"
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="应付金额">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="payableMoney"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.payableMoney"
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column label="应付比例">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="payableRate"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.payableRate"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="应付日期">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="payableTime"
                                    label-width="0px"
                                    style="margin: 0"
                                    value-format="yyyy-MM-dd"
                                    format="yyyy-MM-dd"
                                >
                                    <el-input
                                        v-model="scope.row.payableTime"
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="是否预付">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="isPrepaid"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-checkbox
                                        v-model="scope.row.isPrepaid"
                                    />
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="付款关联金额">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="paymentRelatedAmount"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.paymentRelatedAmount"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="预付单号">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="prepaidCode"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.prepaidCode"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column label="备注">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="remark"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.remark"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>

                        <el-table-column label="单次预付额度">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="singlePrepaidLimit"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.singlePrepaidLimit"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="供应商id">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="supplierId"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.supplierId"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column label="录入人">
                            <template slot-scope="scope">
                                <el-form-item
                                    prop="userId"
                                    label-width="0px"
                                    style="margin: 0"
                                >
                                    <el-input
                                        v-model="scope.row.userId"
                                        clearable
                                    ></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-collapse-item> -->
            </el-collapse>
        </el-form>
        <el-dialog
            v-if="dialog"
            title="选择"
            :visible.sync="dialog"
            append-to-body
            width="70%"
            destroy-on-close
        >
            <term
                v-if="dialogType === 'termsId'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <supplier
                v-else-if="
                    dialogType === 'supplierId' || dialogType === 'providerId'
                "
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <dept
                v-else-if="
                    dialogType === 'deptId' ||
                    dialogType === 'balanceId' ||
                    dialogType === 'receiveId'
                "
                :visible.sync="dialog"
                :deptLevel="deptLevel"
                @getSelectVal="getSelectVal"
            />
            <procurementContract
                v-else-if="dialogType === 'procurementContract'"
                :visible.sync="dialog"
                :currentSupplierId="currentSupplierId"
                @getSelectVal="getSelectVal"
            />
            <material
                v-else-if="
                    dialogType === 'material' || dialogType === 'addmaterial'
                "
                :visible.sync="dialog"
                :name="dialogType"
                @getSelectVal="getSelectVal"
            />
            <Unit
                v-else-if="dialogType === 'Unit'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <payApply
                v-else-if="dialogType === 'payApply'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <saleOrder
                v-else-if="dialogType === 'saleOrder'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <askSheet
                v-else-if="dialogType === 'askSheet'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <rate
                v-else-if="dialogType === 'rate'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <payUser
                v-else-if="dialogType === 'applyName'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <currencys
                v-else-if="dialogType === 'settlementCurrency'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <termOfPayment
                v-else-if="dialogType === 'termOfPayment'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <settlementMethod
                v-else-if="dialogType === 'settlementMethod'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <priceInfoId
                v-else-if="dialogType === 'priceInfoId'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <discountInfoId
                v-else-if="dialogType === 'discountInfoId'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
            <exchangeRateType
                v-else-if="dialogType === 'exchangeRateType'"
                :visible.sync="dialog"
                @getSelectVal="getSelectVal"
            />
        </el-dialog>
    </div>
</template>
<script>
import {
    getOrderDetail,
    addList,
    getDocTypeList,
    editList,
} from "@/api/system/purchase";
import { getList } from "@/api/system/warehouse";
import { getCurrencyData, getPayData } from "@/api/base/data";
import { getDetailProcure } from "@/api/contract/index";
import term from "./dialog/term";
import supplier from "./dialog/supplier";
import dept from "./dialog/dept";
import Unit from "./dialog/units";
import payApply from "./dialog/payApply";
import askSheet from "./dialog/askSheet";
import saleOrder from "./dialog/saleOrder";
import procurementContract from "./dialog/procurementContract";
import material from "./dialog/material";
import rate from "./dialog/rate";
import payUser from "./dialog/payUser";
import currencys from "./dialog/currencys";
import termOfPayment from "./dialog/termOfPayment";
import settlementMethod from "./dialog/settlementMethod";
import exchangeRateType from "./dialog/exchangeRateType";
import priceInfoId from "./dialog/priceInfoId";
import discountInfoId from "./dialog/discountInfoId";
import { getCompute } from "@/api/finance/info";
export default {
    props: ["rowId"],
    components: {
        priceInfoId,
        discountInfoId,
        term,
        supplier,
        dept,
        procurementContract,
        material,
        Unit,
        payApply,
        saleOrder,
        askSheet,
        rate,
        payUser,
        currencys,
        termOfPayment,
        settlementMethod,
        exchangeRateType,
    },
    data() {
        return {
            activeName: ["basic", "orderDetails"],
            dialog: false,
            counties: [],
            orgData: [], //创建组织弹窗列表
            orgSelect: [], //选中项
            orgTotal: "", //创建组织弹窗分页
            dialogType: "",
            dialogIndex: "",
            deatilList: [],
            warehouseList: [], //仓库列表
            currentSupplierId: "",
            deptLevel: "",
            formObject: {
                businessType: "5",
                modelId: this.$store.state.workflow.businessConfig.id,
                originalNumber: "",
                originalContainsTaxPrice: "",
                changeReason: "",
                applyFormUnpaidAmount: "",
                applyId: "",
                applyName: "",
                applyTime: this.parseTime(new Date()),
                baseCurrency: "",
                baseCurrencyName: "",
                changeTime: "",
                factoryTime: this.parseTime(new Date()),
                checkMethod: 0,
                closeName: "",
                closeReason: "",
                closeState: "",
                closeTime: "",
                confirmName: "",
                confirmState: "",
                confirmTime: "",
                createId: "",
                createName: "",
                createTime: "",
                discountInfoId: "",
                discountInfoName: "",
                docBusinessType: "",
                docType: "",
                documentCode: "",
                examineName: "",
                examineTime: "",
                exchangeRate: "",
                exchangeRateType: "",
                focusSettlementDept: "",
                id: "",
                instanceId: "",
                invalidName: "",
                invalidState: "",
                invalidTime: "",
                isExtraPriceTax: true,
                isManualClose: true,
                isTax: true,
                isTemp: true,

                lastUpdateName: "",
                lastUpdateTime: "",
                limit: 0,
                money: "",
                moneyAmount: "",
                moneyAmountBase: "",
                orderDeliveryDetails: [],
                orderDeliverys: [],
                orderDetails: [],
                orderFinanceDetails: [],
                orderNumber: "",
                orderOthers: [],
                orderPaymentExecutions: [],
                orderPaymentPlans: [],
                orderPurchaseTerms: [],
                orderSupplier: {
                    balanceId: "",
                    balanceCode: "",
                    balanceName: "",
                    changeTime: "",
                    createTime: "",
                    email: "",
                    id: "",

                    orderId: "",
                    phone: "",
                    post: "",
                    providerContacts: "",
                    providerId: "",
                    providerCode: "",
                    providerName: "",
                    receiveId: "",
                    receiveName: "",
                    receiveCode: "",
                    userId: "",
                },
                page: 0,
                priceInfoId: "",
                priceInfoName: "",
                pricingTimePoint: this.parseTime(new Date()),
                projectId: "",
                purchaseDept: "",
                purchaseDeptCode: "",
                purchaseGroup: "",
                purchaseOrg: "",
                purchaseOrgLabel: "",
                settlementCurrency: "",
                settlementCurrencyName: "",
                settlementMethod: "",
                settlementMethodName: "",
                sourceDocType: "",
                state: "",
                status: 0,
                supplierId: "",
                supplierCode: "",
                supplierName: "",
                taxAmount: "",
                taxAmountBase: "",
                termOfPayment: "",
                termOfPaymentTitle: "",
                token: "",
                totalPaymentAmount: "",
                totalPaymentApplyAmount: "",
                totalPriceTax: "",
                totalPriceTaxBase: "",
                totalReturnAmount: "",
                updateName: "",
                updateState: "",
                updateTime: "",
                userId: "",
                version: "",
                warehouseId: "",
                wholeDiscountAmount: "",
            },
            documentTypeList: [],
            checkMethodList: [
                { label: "数量验收", value: 0 },
                { label: "金额验收", value: 1 },
                { label: "比例验收", value: 2 },
            ],
            formObjectRules: {
                supplierId: [
                    {
                        required: true,
                        message: "供应商不能为空！",
                        trigger: "change",
                    },
                ],
                factoryTime: [
                    {
                        required: true,
                        message: "日期不能为空！",
                        trigger: "change",
                    },
                ],
                // purchaseOrgLabel: [
                //   {
                //     required: true,
                //     message: "采购部门不能为空！",
                //     trigger: "change",
                //   },
                // ],
                docBusinessType: [
                    {
                        required: true,
                        message: "业务类型不能为空！",
                        trigger: "change",
                    },
                ],
                docType: [
                    {
                        required: true,
                        message: "单据类型不能为空！",
                        trigger: "change",
                    },
                ],
                applyTime: [
                    {
                        required: true,
                        message: "采购日期不能为空！",
                        trigger: "change",
                    },
                ],
                pricingTimePoint: [
                    {
                        required: true,
                        message: "定价时点日期不能为空！",
                        trigger: "change",
                    },
                ],
                settlementCurrency: [
                    {
                        required: true,
                        message: "币别不能为空！",
                        trigger: "change",
                    },
                ],
                warehouseId: [
                    {
                        required: true,
                        message: "仓库不能为空！",
                        trigger: "change",
                    },
                ],
                changeReason: [
                    {
                        required: true,
                        message: "变更原因不能为空！",
                        trigger: "change",
                    },
                ],
                materialCode: [
                    {
                        required: true,
                        message: "物料编码不能为空！",
                        trigger: "change",
                    },
                ],
                pricingUnitName: [
                    {
                        required: true,
                        message: "计价单位不能为空",
                        trigger: "change",
                    },
                ],
            },
        };
    },
    computed: {
        // docBusinessType() {
        //   this.formObject.docBusinessType = this.formObject.docType;
        //   const item = this.documentTypeList.find(
        //     (e) => e.id === this.formObject.docType
        //   );
        //   if (item) {
        //     return item.title;
        //   } else {
        //     return "";
        //   }
        // },
    },
    methods: {
        // 页签切换事件
        handleClick(tab, event) {},
        // 附件上传
        handleFileChange() {
            console.log("文件上传");
        },

        // 基础表单提交
        submit(cb) {
            this.$refs["formObjectRef"].validate((valid) => {
                if (valid) {
                    this.formObject.orderDetails =
                        this.formObject.orderDetails.map((item) => {
                            return {
                                ...item,
                                warehouseId: this.formObject.warehouseId,
                            };
                        });
                    if (this.rowId) {
                        this.formObject.parentId = this.formObject.id;
                        delete this.formObject.id;
                        editList(this.formObject).then((res) => {
                            if (res.code === 200) {
                                cb();
                                this.$message({
                                    message: "修改成功！",
                                    type: "success",
                                });
                            }
                        });
                        return;
                    }
                    addList(this.formObject).then((res) => {
                        if (res.code === 200) {
                            this.$store.commit(
                                "workflow/SET_BUSINESSDRAWER",
                                false
                            );
                            this.$message({
                                message: "新增成功！",
                                type: "success",
                            });
                        }
                    });
                }
            });
        },

        // 删除行
        handleDataDelete(index, row, type) {
            this.$confirm("请确认是否要删除此行？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.$message({
                        type: "success",
                        message: "删除成功!",
                    });
                    if (type == "orderDetails") {
                        this.formObject.orderDetails.splice(index, 1);
                    } else if (type == "orderPaymentPlans") {
                        this.formObject.orderPaymentPlans.splice(index, 1);
                    } else if (type === "orderPurchaseTerms") {
                        this.formObject.orderPurchaseTerms.splice(index, 1);
                    }
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                });
        },

        //明细信息添加行
        addOrderDetails(e, type) {
            let obj = {
                directRate: "",
                indirectRate: "",
                amountMoney: "",
                batchNum: "",
                businessTaxCostPrice: "",
                changeTime: "",
                containsTaxPrice: "",
                createTime: "",
                deliveryAddress: "",
                deliveryDate: this.parseTime(new Date()),
                deliveryLocation: "",
                discountAmount: "",
                discountRate: "",
                id: "",
                inventoryId: "",
                inventoryNum: 0,
                inventoryUnit: "",
                isGiveaway: "",

                limit: 0,
                materialId: "",
                materialCode: "",
                materialName: "",
                noTaxMoney: "",
                model: "",
                number: 0,
                page: 0,
                netAmount: "",
                price: "",
                pricingNum: "",
                pricingUnit: "",
                pricingUnitName: "",
                purchaseUnit: "",
                ramarks: "",
                receivedFirstTicketsNum: "",
                receivingDept: "",
                relationId: "",
                requireDept: "",
                settlementDept: "",
                sourceDocCode: "",
                sourceDocType: "",
                sourceRelationId: "",
                supplierMaterialCode: "",
                supplierMaterialName: "",
                taxAmount: "",
                taxMoney: "",
                taxPrice: "",
                taxRate: "",
                token: "",
                totalAcceptanceAmount: "",
                totalAcceptanceRate: "",
                totalTaxPrice: "",
                type: 0,
                warehouseId: "",
                warehouseRegionId: "",
            };
            if (e) {
                for (const key in obj) {
                    if (e.hasOwnProperty(key)) {
                        if (key === "id") {
                            if (type === "edit") {
                                obj.materialId = e.id;
                            } else {
                                obj.sourceMaterialDetailId =
                                    e.materialDetailId || "";
                                obj.sourceRelationId = e.id;
                            }
                        } else {
                            obj[key] = e[key];
                        }
                    }
                }
                if (type === "edit") {
                    this.$set(
                        this.formObject.orderDetails,
                        this.dialogIndex,
                        obj
                    );
                } else {
                    this.formObject.orderDetails.push(obj);
                }
            } else {
                this.formObject.orderDetails.push(obj);
            }
        },

        //订单条款添加行
        addOrderPaymentPlans() {
            let obj = {
                actualPrepaidAmount: "",
                changeTime: "",
                createTime: "",
                id: "",
                isPrepaid: "",

                orderId: "",
                payableMoney: "",
                payableRate: "",
                payableTime: "",
                paymentRelatedAmount: "",
                prepaidCode: "",
                remark: "",
                singlePrepaidLimit: "",
                supplierId: "",
                userId: "",
            };
            this.formObject.orderPaymentPlans.push(obj);
        },

        //付款计划添加行
        addOrderPurchaseTerms() {
            let obj = {
                changeTime: "",
                createTime: "",
                describe: "",
                id: "",

                orderId: "",
                purchaseTermsId: "",
                userId: "",
            };
            this.formObject.orderPurchaseTerms.push(obj);
        },

        //添加新行
        addNewRow(type) {
            if (type === "orderDetails") {
                this.addOrderDetails();
            } else if (type === "orderPaymentPlans") {
                this.addOrderPaymentPlans();
            } else if (type === "orderPurchaseTerms") {
                this.addOrderPurchaseTerms();
            }
        },
        getSelectVal(val) {
            console.log("this.dialogType", this.dialogType, val);
            if (this.dialogType === "termsId") {
                this.formObject.orderPurchaseTerms[this.dialogIndex].id =
                    val[0].id;
                this.formObject.orderPurchaseTerms[
                    this.dialogIndex
                ].sourceRelationId = val[0].id;
            } else if (this.dialogType === "supplierId") {
                this.formObject.supplierId = val[0].id;
                this.formObject.supplierCode = val[0].supplierCode;
                this.formObject.supplierName = val[0].supplierName;
            } else if (this.dialogType === "providerId") {
                this.formObject.orderSupplier.providerId = val[0].id;
                this.formObject.orderSupplier.providerCode =
                    val[0].supplierCode;
                this.formObject.orderSupplier.providerName =
                    val[0].supplierName;
            } else if (this.dialogType === "deptId") {
                this.formObject.purchaseDept = val[0].deptId;
                this.formObject.purchaseDeptCode = val[0].deptCode;
                this.formObject.purchaseOrgLabel = val[0].deptName;
            } else if (this.dialogType === "balanceId") {
                this.formObject.orderSupplier.balanceId = val[0].deptId;
                this.formObject.orderSupplier.balanceCode = val[0].deptCode;
                this.formObject.orderSupplier.balanceName = val[0].deptName;
            } else if (this.dialogType === "receiveId") {
                this.formObject.orderSupplier.receiveId = val[0].deptId;
                this.formObject.orderSupplier.receiveCode = val[0].deptCode;
                this.formObject.orderSupplier.receiveName = val[0].deptName;
            } else if (this.dialogType === "termOfPayment") {
                this.formObject.termOfPayment = val[0].conditionCode;
                this.formObject.termOfPaymentTitle = val[0].title;
            } else if (this.dialogType === "settlementCurrency") {
                this.formObject.settlementCurrency = val[0].code;
                this.formObject.settlementCurrencyName = val[0].currencyName;
                this.formObject.exchangeRate = val[0].rate;
                this.formObject.baseCurrencyName = val[0].currencyName;
                this.formObject.baseCurrency = val[0].code;
            } else if (this.dialogType === "settlementMethod") {
                this.formObject.settlementMethod = val[0].bizCode;
                this.formObject.settlementMethodName = val[0].title;
            } else if (this.dialogType === "exchangeRateType") {
                this.formObject.exchangeRateType = val[0].code;
            } else if (this.dialogType === "discountInfoId") {
                this.formObject.discountInfoId = val[0].id;
                this.formObject.discountInfoName = val[0].name;
            } else if (this.dialogType === "priceInfoId") {
                this.formObject.priceInfoId = val[0].id;
                this.formObject.priceInfoName = val[0].name;
            } else if (this.dialogType === "material") {
                if (val.length) {
                    this.addOrderDetails(val[0], "edit");
                }
            } else if (this.dialogType === "addmaterial") {
                if (val.length) {
                    val.forEach((e) => {
                        this.addOrderDetails(e);
                    });
                }
            } else if (this.dialogType === "procurementContract") {
                this.currentSupplierId = val[0].supplierId;
                val.forEach((e) => {
                    this.addOrderDetails(e);
                });
                getDetailProcure(val[0].id).then((res) => {
                    this.formObject.supplierName =
                        res.data.contractProcureEntity.supplierName;
                    this.formObject.purchaseDept =
                        res.data.contractProcureEntity.deptId;
                    this.formObject.applyTime =
                        res.data.contractProcureEntity.signTime;
                });
            } else if (this.dialogType === "Unit") {
                this.formObject.orderDetails[this.dialogIndex].pricingUnitName =
                    val[0].meteringUnitName;
                this.formObject.orderDetails[this.dialogIndex].pricingUnit =
                    val[0].meteringUnitCode;
            } else if (this.dialogType === "payApply") {
                val.forEach((e) => {
                    this.addOrderDetails(e);
                });
            } else if (this.dialogType === "saleOrder") {
                val.forEach((e) => {
                    this.addOrderDetails(e);
                });
            } else if (this.dialogType === "askSheet") {
                val.forEach((e) => {
                    this.addOrderDetails(e);
                });
            } else if (this.dialogType === "rate") {
                this.formObject.orderDetails[this.dialogIndex].directRate =
                    val[0].directRate;
                this.formObject.orderDetails[this.dialogIndex].indirectRate =
                    val[0].indirectRate;
                this.changeNumber(
                    this.dialogIndex,
                    this.formObject.orderDetails[this.dialogIndex]
                );
            } else if (this.dialogType === "applyName") {
                this.formObject.applyName = val[0].userId;
                this.formObject.applyId = val[0].applyId;
            }
        },

        //汇率变化
        rateChange(row, index) {
            if (!row.directRate || !row.indirectRate) {
                row.directRate = "";
                row.indirectRate = "";
                this.$set(this.formObject.orderDetails, index, row);
            }
        },
        //点击选择dialog中的一条数据回显
        addDialog(type, index) {
            console.log("addDialog", type);
            this.dialog = true;
            this.dialogType = type;
            this.dialogIndex = index;
            if (type === "balanceId" || type === "receiveId") {
                this.deptLevel = 1;
            } else if (type === "deptId") {
                this.deptLevel = 2;
            }
        },
        //获取单据类型
        getDocTypeListApi() {
            getDocTypeList({ docCode: "PUR_PurchaseOrder" }).then((res) => {
                if (res.code === 200) {
                    this.documentTypeList = res.rows;
                    this.formObject.docType = res.rows[0].docCode;
                }
            });
        },
        //获取仓库
        getWareHouseList() {
            getList().then((res) => {
                if (res.code === 200) {
                    this.warehouseList = res.rows.map((item) => {
                        return {
                            label: item.wareName,
                            value: item.id,
                        };
                    });
                }
            });
        },
        //下拉类型选择
        handleCommand(val) {
            this.dialogType = val;
            this.dialog = true;
            // this.activeName = "orderDetails";
        },

        // 数量，税率，价税金额计算
        changeNumber(index, row) {
            if (
                !row.number ||
                !row.taxRate ||
                !row.totalTaxPrice ||
                !row.directRate
            ) {
                return;
            }
            getCompute({
                number: row.number,
                taxRate: row.taxRate,
                totalTaxAmount: row.totalTaxPrice,
                rate: row.directRate,
            }).then((res) => {
                if (res.code === 200) {
                    row.price = res.data.price;
                    row.taxPrice = res.data.taxUnitPrice;
                    row.taxAmount = res.data.taxAmount;
                    row.amountMoney = res.data.amount;
                    this.$set(this.formObject.orderDetails, index, row);
                }
            });
        },
    },
    created() {
        this.getDocTypeListApi();
        this.getWareHouseList();
        //币别
        getCurrencyData().then((res) => {
            this.formObject.settlementCurrencyName = res.rows[0].currencyName;
            this.formObject.settlementCurrency = res.rows[0].code;
            this.formObject.exchangeRate = res.rows[0].rate;
            this.formObject.baseCurrencyName = res.rows[0].currencyName;
            this.formObject.baseCurrency = res.rows[0].code;
        });
        //付款条件
        getPayData().then((res) => {
            this.formObject.termOfPaymentTitle = res.rows[0].conditionDesc;
            this.formObject.termOfPayment = res.rows[0].id;
        });
        if (this.rowId) {
            getOrderDetail(this.rowId).then((res) => {
                if (res.code === 200) {
                    this.formObject = res.data;
                    this.formObject.orderDetails.forEach((e) => {
                        e.originalNumber = e.number;
                        e.originalContainsTaxPrice = e.taxPrice;
                    });
                }
            });
        }
    },
};
</script>
<style lang="scss" scoped>
// .add {
//   padding: 15px;
// }
.panel-title {
    font-size: 18px;
    color: #37474f;
    font-weight: 500;
    text-shadow: rgba(0, 0, 0, 0.15) 0 0 1px;
}

::v-deep .el-form-item__content {
    margin-left: 0;
}

.main-responsible {
    font-size: 14px;
    font-weight: 550;
    color: #263238;
    position: relative;
    text-indent: 15px;
}
::v-deep .el-table td.el-table__cell div {
    overflow: visible;
}

::v-deep .el-table td.el-table__cell {
    padding-bottom: 20px;
}
</style>
